from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, sessionmaker

from config.config_db import DATABASE_URL

"""
提供数据库操作的基础功能
"""

def engine_settings():
    return {
        'url': str(DATABASE_URL),
        'echo': False,
        # 'echo': True,
    }

def get_db_session():
    db_session = Session()
    try:
        yield db_session
    finally:
        db_session.close()


engine = create_engine(**engine_settings())

Session = sessionmaker(bind=engine)

Base = declarative_base()
